﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Pacjent
{
    public partial class pdodajpac : PhoneApplicationPage
    {
        static referencja1.Service1SoapClient c;
        int iddaty = 0;
        int flaga = 0;

        public pdodajpac()
        {
            c = new referencja1.Service1SoapClient();
            InitializeComponent();
            c.dodajpacjentaCompleted += new EventHandler<referencja1.dodajpacjentaCompletedEventArgs>(c_dodajpacjentaCompleted);
            c.pobierziddatyCompleted += new EventHandler<referencja1.pobierziddatyCompletedEventArgs>(c_pobierziddatyCompleted);
            c.dodajdatyCompleted += new EventHandler<referencja1.dodajdatyCompletedEventArgs>(c_dodajdatyCompleted);
            c.pobierziddatyAsync();
        }

        void c_dodajdatyCompleted(object sender, referencja1.dodajdatyCompletedEventArgs e)
        {
            flaga++;
        }

        void c_pobierziddatyCompleted(object sender, referencja1.pobierziddatyCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                iddaty = int.Parse(e.Result)+1;
            }
            else
            {
                MessageBox.Show("blad");                
            }
        }

        void c_dodajpacjentaCompleted(object sender, referencja1.dodajpacjentaCompletedEventArgs e)
        {
            MessageBox.Show("poprawnie dodano pacjenta");
        }
        private void PowrotDoMenu()
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }

        private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
        {
            PowrotDoMenu();
        }

        private void hyperlinkButton2_Click(object sender, RoutedEventArgs e)
        {
            PowrotDoMenu();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == "")
            { MessageBox.Show("Sprawdz pesel");}
            else if (textBox2.Text == "")
            { MessageBox.Show("Sprawdz Imie"); }
            else if (textBox3.Text == "")
            { MessageBox.Show("Sprawdz Nazwisko"); }
            else if (textBox4.Text == "")
            { MessageBox.Show("Sprawdz Adres"); }
            else if (textBox5.Text == "")
            { MessageBox.Show("Sprawdz Uwagi"); }
            else if (textBox6.Text == "")
            { MessageBox.Show("Sprawdz Alergie"); }
            else if (textBox7.Text == "")
            { MessageBox.Show("Sprawdz Choroby przewlekle"); }
            else if (textBox9.Text == "")
            { MessageBox.Show("Sprawdz Obecna chorobe"); }
            else
            {
                c.dodajpacjentaAsync(textBox2.Text, textBox3.Text, textBox1.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox9.Text, textBox9.Text);
                c.dodajdatyAsync(iddaty.ToString(), textBox1.Text, "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");            
            }
        }       
    }
}